<template>
  <div class="editor-main">
    <v-md-editor
      mode="edit"
      placeholder="请输入内容"
      v-model="props.issuesData.content"
      height="420px"
      @copy-code-success="handleCopyCodeSuccess"
      :disabled-menus="[]"
      @upload-image="handleUploadImage"
    ></v-md-editor>
  </div>
</template>

<script lang="ts" setup>
import { PropType } from 'vue'

import { getToken } from '@/utils/token-cache'
import { Issues } from '@/views/issues/config/issues'

import Request from '@/apis/index'

const props = defineProps({
  issuesData: {
    type: Object as PropType<Issues>,
    default: () => {}
  }
})

/**
 * @desc: 图片上传
 */
const baseUrl = 'https://dwh_api.bimcc.net'
const handleUploadImage = (event: any, insertImage: any, files: any) => {
  return new Promise((reslove, resject) => {
    const data = new FormData()
    for (let i in files) {
      data.append('file', files[i])
    }
    Request.post({
      url: `${baseUrl}/api/mapi?__method_name__=file` + '&token=' + getToken(),
      data: data
    }).then((res) => {
      if (res && res.data.url) {
        insertImage({
          url: res.data.url,
          desc: res.data.filename,
          width: 'auto',
          height: 'auto'
        })
        reslove(res.data.url.replace('_thumb', ''))
      } else {
        resject('上传失败')
      }
    })
  })
}

/**
 * @desc: 图片复制
 * @param {*} code
 * @return {*}
 */
const handleCopyCodeSuccess = (code: string) => {
}
</script>

<style scoped></style>
